home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_3a.arc / NEURAL.BAS < prev    next >
BASIC Source File  |  1989-04-20  |  2KB  |  82 lines

  1. REM Code fragments from "Neural Nets" by Tom Waite and Hal Hardenbergh
  2.  
  3. REM Here are steps 2 through 4 of the Recall Computations
  4. REM translated into BASIC
  5.  
  6. for j = 1 to J
  7.     sum = Ibias(j)
  8.     for i = 1 to I
  9.         sum = sum + Input(i)*Iwt(i,j)
  10.     next i
  11.     Iout(j) = 1/(1+exp(-sum))
  12. next j
  13.  
  14. for k = 1 to K
  15.     sum = Cbias(k)
  16.     for j = 1 to J
  17.         sum = sum + Iout(j)*Cwt(j,k)
  18.     next j
  19.     Cout(k) = 1/(1+exp(-sum))
  20. next k
  21.  
  22. for l = 1 to L
  23.     sum = Obias(l)
  24.     for k = 1 to K
  25.         sum = sum + Cout(k)*Owt(k,l)
  26.     next k
  27.     Oout(l) = 1/(1+exp(-sum))
  28. next l
  29.  
  30. REM The Learning Computations
  31. REM Step 5: Get the output-layer error and error term (Odelta)
  32. REM and update weights and bias while computing a portion of the 
  33. REM center-layer error term:
  34.  
  35. REM initialize Cdelta()=0   (zero the entire array)
  36. for l=1 to L
  37.     Error(ts,l)=Target(ts,l)-Oout(l)
  38.     Odelta=Oout(l)*(1-Oout(l))*Error(ts,l)
  39.     for k=1 to K
  40.         temp=OwtN(k,l)
  41.         OwtN(k,l)=OwtN(k,l)+Nu*Odelta*Cout(k)+alpha*(OwtN(k,l)-OwtP(k,l))
  42.         OwtP(k,l)=temp
  43.         pCdelta(k)=pCdelta(k)+Odelta*OwtN(k,l)
  44.     next k
  45.     temp=ObiasN(l)
  46.     ObiasN(l)=ObiasN(l)+nu*Odelta+alpha*(ObiasN(l)-ObiasP(l))
  47.     ObiasP(l)=temp
  48. next l
  49.  
  50. REM Step 6: Get the center-layer error term and update weights and
  51. REM bias while computing a portion of the input-layer error term:
  52.  
  53. REM initialize Idelta()=0   (zero the entire array)
  54. for k=1 to K
  55.     Cdelta=Cout(k)*(1-Cout(k))*pCdelta(k)
  56.     for j=1 to J
  57.         temp=CwtN(j,k)
  58.         CwtN(j,k)=CwtN(j,k)+Nu*Cdelta*Iout(j)+alpha*(CwtN(j,k)-CwtP(j,k))
  59.         CwtP(j,k)=temp
  60.         pIdelta(j)=pIdelta(j)+Cdelta*CwtN(j,k)
  61.     next j
  62.     temp=CbiasN(k)
  63.     CbiasN(k)=CbiasN(k)+Nu*Cdelta+alpha*(CbiasN(k)-CbiasP(k))
  64.     CbiasP(k)=temp
  65. next k
  66.  
  67. REM Step 7: Get the input-layer error term and update weights and bias:
  68.  
  69. for j=1 to J
  70.     Idelta=Iout(j)*(1-Iout(j))*pIdelta(j)
  71.     for i=1 to I
  72.         temp=IwtN(i,j)
  73.         IwtN(i,j)=IwtN(i,j)+Nu*Idelta*Input(ts,i)+alpha*(IwtN(i,j)-IwtP(i,j))
  74.         IwtP(i,j)=temp
  75.     next i
  76.     temp=IbiasN(j)
  77.     IbiasN(j)=IbiasN(j)+Nu*Idelta+alpha*(IbiasN(j)-IbiasP(j))
  78.     IbiasP(j)=temp
  79. next j
  80.  
  81.  
  82.